home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 4602 < prev    next >
Encoding:
Internet Message Format  |  1996-08-06  |  1.5 KB

  1. Path: svnews.ubinet.ubs.com!ubszh!ubszh!jis
  2. From: ian.johnston@ubs.com (Johnston Ian (by ubsswop))
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: Newbie question on syntax of pointer to const
  5. Date: 31 Jan 1996 08:25:13 GMT
  6. Organization: UBS
  7. Distribution: world
  8. Message-ID: <4en919$o1h@ubszh.fh.zh.ubs.com>
  9. References: <4ej9eg$lq6@agate.berkeley.edu> <4ek468$jr1@clarknet.clark.net> <4ell6p$3f2q@yuma.ACNS.ColoState.EDU>
  10. NNTP-Posting-Host: nol2179.fh.zh.ubs.com
  11.  
  12. In article <4ell6p$3f2q@yuma.ACNS.ColoState.EDU>, steffend@lamar.colostate.edu (Dave Steffen) writes:
  13. |> Harlan Messinger (gusty@clark.net) wrote:
  14. |> > parsons@vouvray.CS.Berkeley.EDU (David C. Parsons) wrote:
  15. |> > >(1)    const double *pc;    and
  16. |> > >(2)    double const *pc;
  17. |> 
  18. |> > This is one of my favorite questions to ask C/C++ programmers at job
  19. |> > interviews.
  20. |> 
  21. |> > They are different. The first is a pointer to a constant double.
  22. |> (snip)
  23. |> > The second is a constant pointer to a double.
  24. |> (snip)
  25.  
  26. Wrong. They are the same: a pointer to a const double.
  27.  
  28. We went through all this about two months back. I hope Harlan Messinger
  29. never interviews me for a C++ job :-) :-) (Pity this didn't appear during
  30. that thread about c++ interviews ...)
  31.  
  32. |> 
  33. |>     What I'm curious about is the syntax of that second
  34. |> line. Looking at Meyers' book, it looks like the const should come
  35. |> after the *. In other words, are these the same:
  36. |> 
  37. |> double const * pc;
  38. |> double * const pc;
  39.  
  40. The second one is absolutely correct if you want a constant pointer to
  41. a (mutable) double.
  42.  
  43. Ian
  44.